<?php
/* 
* [企业基本信息管理模型]
* @author: mazhenyu[houdunwangmzy@163.com]
* @Date:   2014-07-02 08:31:49
* @Last Modified time: 2014-07-02 08:59:08
*/

class ComInfoModel extends Model{
	public $table = "company_baseinfo";


	public $validate = array(
		array("companyname", "nonull", "公司名称不能为空", 2, 3),
        array("nature", "num:1,9", "企业性质选择错误", 2, 3),
        array("city_one", "regexp:/^\d+$/", "公司所在地选择错误", 2, 3),
        array("city_second", "regexp:/^\d+$/", "公司所在地选择错误", 2, 3),
        array("scale" ,"num:1,6", "请选择公司规模", 2, 3),
        array("registermoney", "nonull", "注册资金不能为空", 3, 3),
        array("companypeople", "nonull", "联系人不能为空", 2, 3),
        array("companynumber", "phone", "联系电话格式错误", 2, 3),
        array("companymail", "email", "邮箱填写错误", 2, 3),
        array("moneytype", "num:1,2", "注册资金填写错误", 2, 1),
        array("companyintro", "minlen:30", "公司简介不能小于30个字符", 2, 3)

		);

	public $auto = array(
		array('user_uid', '_uid', 'method', 2, 1),
		array('city_cityid', '_cityId', 'method', 2, 3),
		array('addtime', '_addtime', 'method', 2, 1),
		);

	public function _addtime(){
		return time();
	}

	public function _uid(){
		return session('uid');
	}

	public function _cityId(){
		$cityOne = Q('post.city_one', 0, 'intval');
		$citySecond = Q('post.city_second', 0, 'intval');

		//如果二级城市不为0，就记录2级城市id,否则就记录1级城市id
		if($citySecond !=0){
			return $citySecond;
		}
		// 否则就记录1级城市id
		return $cityOne;
	}

	/**
	 * [have_info 判断基本信息表是否有数据]
	 * @return [type] [description]
	 */
	public function have_info(){
		return $this->where(array('user_uid'=>session('uid')))->getField('cbid');
	}

	 /**
     * [get_info 获得基本信息]
     * @param  [type] $uid   [当前用户uid]
     * @param  [type] $field [字段名称]
     * @return [type]        [description]
     */
    public function get_info($uid,$field = NULL){
    	return $this->where(array('user_uid'=>$uid))->field($field)->find();
    }
     /**
     * [update_data 通过uid修改企业基本信息]
     * @param  [type] $uid  企业基本信息用户uid
     * @return [type]
     */
    public function update_data(){
        //执行修改
        $this->where(array('user_uid'=>session('uid')))->save();
    }

    public function add_data(){
    	return $this->add();
    }
}
?>
